package com.ruoyi.framework.youshuda.quartzTask;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.zgl.youshuda.core.service.procservice.InterDealProcService;
import com.zgl.youshuda.core.utils.OperResult;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 定时任务调度优树搭
 * 请勿删除或修改服务名与方法名
 */
@lombok.extern.slf4j.Slf4j
@Slf4j
@Component("ysdTask")
public class YsdTask {

    @Autowired
    private InterDealProcService ysdProcService;

    public void run(String ysdApiCode, String params) {
        /** 参数解析， **/
        Map paramObj = null;
        if (StringUtils.isNotEmptyIncludeNull(params)) {
            try{
                paramObj = JSONObject.parseObject(params, Map.class);
            }catch (Exception e){
                log.error("定时调用优树搭执行【失败】，原因：参数异常，参数格式：{param1:val1,param2:val2}，当前异常参数为：{}", params);
                return;
            }
        }
        /** 调用优树搭 **/
        OperResult operResult = ysdProcService.dealProc(ysdApiCode, paramObj);
        if (operResult.isSuccess()){
            log.debug("定时调用优树搭执行【成功】");
        }else{
            log.error("定时调用优树搭执行【失败】，原因：{}",operResult.getMsg());
        }

    }
}
